/**
 * 2017年4月25日
 */
package cn.edu.bjtu.labsys.settings;

import java.io.IOException;
import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import listener.AppContextListener;
import pojo.dto.sys.Tuple2;

/**
 * @author Alex
 *
 */
public class ApplicationConfiguration extends Properties{
	private ApplicationConfiguration(){
		try{
			this.load(AppContextListener.class.getResourceAsStream("/conf/appConfig.properties"));
			this.load(AppContextListener.class.getResourceAsStream("/config.properties"));
			this.load(AppContextListener.class.getResourceAsStream("/config-train.properties"));
			this.load(AppContextListener.class.getResourceAsStream("/config-test.properties"));
		} catch (IOException e) {
			System.out.print("config properties load error");
		}	
	}
	private static final long serialVersionUID = 1639498280356484991L;
	public static ApplicationConfiguration getInstance(){
		if(instance == null){
			synchronized (ApplicationConfiguration.class) {
				if(instance == null){
					instance = new ApplicationConfiguration();
				}
			}
		}
		return instance;
	}
	
	private static ApplicationConfiguration instance = null;
	public List<Tuple2> toPairs(){
		List<Tuple2> res = new ArrayList<Tuple2>();
		for(Object o:this.keySet()){
			res.add(new Tuple2(o.toString(), this.getProperty((String) o).toString()));
		}
		return res;
	}
	private Object readResolve() throws ObjectStreamException{
		return instance;
	}
	
}
